﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Text;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Web;
using IronOne.SalesOne.DataObjects.QuotationReportDSTableAdapters;

namespace IronOne.SalesOne.SalesOneWeb.SalesQuotations
{
    public partial class ViewReportChild5 : System.Web.UI.Page
    {
        string lifeCode = string.Empty;
        string quoNum = string.Empty;

        protected void Page_Load(object sender, EventArgs e)
        {

            quoNum = Page.Request.Params["QuotationNum"].ToString();
            lifeCode = Page.Request.Params["Life"].ToString();

            ReportDocument RptCodes = new ReportDocument();
            CodesQuoTableAdapter CdAdp = new CodesQuoTableAdapter();

            DataTable dt1 = CdAdp.GetDataByCodes("MNLIFE", quoNum);



            ReportDocument RptPrem = new ReportDocument();
            PremiumQuoTableAdapter PrAdp = new PremiumQuoTableAdapter();

            DataTable dt2 = PrAdp.GetDataByPremium("MNLIFE", quoNum);



            ReportDocument RptCodes1 = new ReportDocument();
            CodesQuoTableAdapter CdAdp1 = new CodesQuoTableAdapter();

            DataTable dt4 = CdAdp.GetDataByCodes(lifeCode, quoNum);



            ReportDocument RptPrem1 = new ReportDocument();
            PremiumQuoTableAdapter PrAdp1 = new PremiumQuoTableAdapter();

            DataTable dt5 = PrAdp.GetDataByPremium(lifeCode, quoNum);


            ReportDocument RptNotice = new ReportDocument();
            NoticeQuoTableAdapter NtAdp = new NoticeQuoTableAdapter();
            DataTable dt6 = NtAdp.GetDataNotice(quoNum);


            ReportDocument SPReport = new ReportDocument();
            string reportPath = Server.MapPath("ReportChild5.rpt");
            SPReport.Load(reportPath);

            SalesQuotationAdpTableAdapter SQAdpt = new SalesQuotationAdpTableAdapter();

            DataTable dt0 = SQAdpt.GetlSalesQuotation(lifeCode, quoNum);

         //   SPReport.OpenSubreport("SbReportCodes.rpt").SetDataSource((DataTable)dt1);

         //   SPReport.OpenSubreport("SbReportPremium.rpt").SetDataSource((DataTable)dt2);

            SPReport.OpenSubreport("SbReportCodes1.rpt").SetDataSource((DataTable)dt4);

            SPReport.OpenSubreport("SbReportPremium1.rpt").SetDataSource((DataTable)dt5);

            SPReport.OpenSubreport("SbReportNoticeOther.rpt").SetDataSource((DataTable)dt6);



            SPReport.SetDataSource((DataTable)dt0);


            CrystalReportViewer1.ReportSource = SPReport;

            MemoryStream oStream; // using System.IO
            oStream = (MemoryStream)
            SPReport.ExportToStream(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat);
            Response.Clear();
            Response.Buffer = true;
            Response.ContentType = "application/pdf";
            Response.BinaryWrite(oStream.ToArray());
            Response.End();




        }
    }
}
